package com.qeado.site.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.qeado.admin.common.BaseConstData;
import com.qeado.common.helper.AttributeHelper;
import com.qeado.site.model.FriendlyLink;
import com.qeado.site.service.LinkManageService;

@Controller
public class LinkManageController {

	@Autowired
	private LinkManageService linkManageService;
	
	@RequestMapping("/linkSave.ac")
	public String linkSave(HttpServletRequest request, FriendlyLink friendlyLink){
		friendlyLink.setCreator(request.getSession().getAttribute(BaseConstData.USER_ID).toString());
		String message = this.linkManageService.saveNewFriendlyLink(friendlyLink);
		List<FriendlyLink> linkList = this.linkManageService.searchFriendlyLink(null);
		request.setAttribute("message", message);
		request.setAttribute("linkList", linkList);
		return "site/link_manage";
	}
	
	@RequestMapping("/friendlyLinkManage.ac")
	public ModelAndView linkSearch(HttpServletRequest request, FriendlyLink friendlyLink){
		AttributeHelper.removeSessionAttribute(request, "T_");
		List<FriendlyLink> linkList = this.linkManageService.searchFriendlyLink(null);
		return new ModelAndView("site/link_manage","linkList",linkList);
	}
	
	@RequestMapping("/deleteLink.ac")
	public ModelAndView deleteLink(FriendlyLink friendlyLink){
		this.linkManageService.deleteLink(friendlyLink);
		List<FriendlyLink> linkList = this.linkManageService.searchFriendlyLink(null);
		return new ModelAndView("site/link_manage","linkList",linkList);
	}
	
}
